﻿@model FI.BatchJob.Web.Data.Entitities.MailConfig
@{
    ViewData["Title"] = "邮件设置参数";
    int id = 0;
}

<!-- Content Header (Page header) -->
<section class="content-header">
    <h1>
        邮件设置参数
        <small></small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-map-marker"></i> 邮件设置参数</a></li>
        <li><a href="#">参数管理</a></li>
        <li class="active">参数</li>
    </ol>
</section>
<!-- Main content -->
<section class="content">
    <!-- Default box -->
    <div class="box">
        <div class="box-header with-border">
            <h3 class="box-title">所有参数</h3>
            <div class="box-tools pull-right">
                <button type="button" class="btn btn-box-tool" data-widget="collapse" data-toggle="tooltip"
                        title="Collapse">
                    <i class="fa fa-minus"></i>
                </button>
                <button type="button" class="btn btn-box-tool" data-widget="remove" data-toggle="tooltip" title="Remove">
                    <i class="fa fa-times"></i>
                </button>
            </div>
        </div>
        <div class="box-body">
            <!-- Main content -->
            <section class="content">
                <form onsubmit="return SubmitAddEdit(this)">
                    <div class="box-body">
                        <div asp-validation-summary="ModelOnly" class="text-danger"></div>
                        <input type="hidden" asp-for="ID" />
                        <div class="form-group">
                            <label for="Value2" class="control-label">邮件主机</label>
                            <input asp-for="MailHost" class="form-control" />
                            <span asp-validation-for="MailHost" class="text-danger"></span>
                        </div>
                        <div class="form-group">
                            <label for="Value" class="control-label">发件人</label>
                            <input asp-for="MailFrom" class="form-control" />
                            <span asp-validation-for="MailFrom" class="text-danger"></span>
                        </div>
                        <div class="form-group">
                            <label for="Value2" class="control-label">用户名</label>
                            <input asp-for="MailUser" class="form-control" />
                            <span asp-validation-for="MailUser" class="text-danger"></span>
                        </div>
                        <div class="form-group">
                            <label for="Value2" class="control-label">邮件密码</label>
                            <input asp-for="MailPwd" class="form-control" />
                            <span asp-validation-for="MailPwd" class="text-danger"></span>
                        </div>
                        <div class="form-group">
                            <label for="Value2" class="control-label">收件人</label>
                            <input asp-for="MailTo" class="form-control" />
                            <span asp-validation-for="MailTo" class="text-danger"></span>
                        </div>
                    </div>

                    <div class="box-footer">
                        <button type="submit" class="btn btn-primary pull-right"><i class="fa fa-save"></i> 保存</button>
                        <button type="button" class="btn btn-default pull-left" data-dismiss="modal">取消</button>
                    </div>
                </form>

            </section>
        </div>
        <!-- /.box-body -->
    </div>
    <!-- /.box -->
</section>
<!-- /.content -->


@section Scripts{
    @await Html.PartialAsync("_ValidationScriptsPartial")

    <script>
        $(function () {



        });

        function SubmitAddEdit(form) {
            $.validator.unobtrusive.parse(form);
            if ($(form).valid()) {
                var data = $(form).serializeJSON();
                //data = JSON.stringify(data);
                $.ajax({
                    type: 'POST',
                    url:  '/MailConfig/Save',
                    data: data,
              
                    success: function (data) {
                        if (data.success) {
                            ShowMessage(data.message);
                        } else {
                            ShowMessageError(data.message);
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        if (errorThrown === 'Unauthorized') {
                            ShowMessageError("Session 过期，请重新登录");
                            window.location.href = "/Account/Login";
                        } else {
                            ShowMessageError(textStatus);
                        }
                    }
                });

            }
            return false;
        }
    </script>
}